/* GUI CONVERTED from rcshmta1.i (converter v1.76) Thu Apr 11 05:26:18 2002 */
/* rcshmta1.i - Release Management Cyclical Container Check                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.3.1.2 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3    LAST MODIFIED: 02/22/96      BY: AIS *G1NT*               */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98      BY: *K1Q4* Alfred Tan        */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00      BY: *N0KP* Mark Brown        */
/* $Revision: 1.3.1.2 $    BY: Jean Miller       DATE: 04/09/02  ECO: *P058*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

define variable abs_loop_found as logical no-undo.
define variable sub_container like abs_cont_id no-undo.

define buffer abscyc1 for abs_mstr.
define buffer abscyc2 for abs_mstr.

sub_container = "C" + input abs_cont_id.

abs_loop_found = false.

/* We need to work our way up the links.  Since the sub-    */
/* container's parent hasn't been updated yet, we need to   */
/* check both a) did we find a container whose container is */
/* this one, and b) did we find a container whose parent is */
/* sub-container we are identifying                         */

if abs_loop_found = false and abs_mstr.abs_par_id > ""
then do for abscyc1:

   find abscyc1 no-lock where recid(abscyc1) = recid(abs_mstr).

   repeat:

      if available abscyc1 and abscyc1.abs_par_id > ""
      then do:

         if abscyc1.abs_par_id = abs_mstr.abs_id
         or abscyc1.abs_par_id = sub_container
         then do:
            abs_loop_found = true.
            leave.  /* repeat block */
         end.

         /* we haven't identified an infinite loop, so now we     */
         /*  move up one level, to this container's parent        */
         find abscyc2 no-lock where recid(abscyc2) = recid(abscyc1).
         find abscyc1 no-lock
            where abscyc1.abs_shipfrom = abscyc2.abs_shipfrom
            and abscyc1.abs_id = abscyc2.abs_par_id no-error.

      end.
      else
         leave.  /* repeat block */

   end.

end.

if abs_loop_found
   and not (lastkey = keycode("F5") or lastkey = keycode("CTRL-D"))
then do:
   /* Cyclic relationship not allowed */
   {pxmsg.i &MSGNUM=599 &ERRORLEVEL=3}
   undo, retry.
end.

/* end of code to check for infinite loop */
